package test.yzx.pproject.act2;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import test.yzx.pproject.R;
import test.yzx.pproject.view.HomeCenterLayout;
import test.yzx.pproject.view.HomeNumberLayout;
import test.yzx.pproject.view.HomeRingPercentView;

public class CleanMyAndroidActivity extends AppCompatActivity {

    private HomeRingPercentView mspv;
    private HomeNumberLayout nv;
    private HomeCenterLayout layout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.clean_my_android);
        mspv = (HomeRingPercentView) findViewById(R.id.msv);
        nv = (HomeNumberLayout) findViewById(R.id.nv);
        layout = (HomeCenterLayout) findViewById(R.id.layout);
        layout.setCanResponseClickEvent(false);

        mspv.setProgress(100, false);
        mspv.setAnimDuration(1600);

        mspv.setOnAnimEndListener(new HomeRingPercentView.OnAnimEndListener() {
            public void onEnd(HomeRingPercentView view) {
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        layout.showView(R.id.iconView, true);
                        layout.setCanResponseClickEvent(true);
                        layout.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                layout.showView(nv, false);
                                layout.setCanResponseClickEvent(false);

                                int vv = getRandom();
                                mspv.setProgress(vv, true);
                                nv.setNumber(vv, true);
                            }
                        });
                    }
                },300);
            }
        });


        nv.setDuration(mspv.getAnimDuration());
        nv.setNumber(100, false);


        getWindow().getDecorView().postDelayed(new Runnable() {
            public void run() {
                int v = getRandom();
                mspv.setProgress(v, true);
                nv.setNumber(v, true);
            }
        },1000);

    }


    private int getRandom(){
        return (int) (Math.random() * 100);
    }

}
